//
//  MyTopTableViewCell.m
//  Toyohu
//
//  Created by Heige on 16/4/12.
//  Copyright © 2016年 celia. All rights reserved.
//

#import "MyTopTableViewCell.h"
#import "LocalFileManager.h"
#import "HPMe.h"
#import "HPChildren.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "GPCustomMD.h"
#import "GPAFNetworking3.h"


@implementation MyTopTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.headImage.layer.cornerRadius = self.headImage.frame.size.width/2;
    self.headImage.layer.borderColor = [UIColor whiteColor].CGColor;
    self.headImage.clipsToBounds = YES;
    self.headImage.layer.borderWidth = 3;
    

    if ([LocalFileManager getImageForKey:@"backGroundView"]) {
        self.bgImage.image = [LocalFileManager getImageForKey:@"backGroundView"];
    } else {
        self.bgImage.image = [UIImage imageNamed:@"first-figure"];
    }
    
//    if ([LocalFileManager getImageForKey:@"myUserImg"]) {
//        self.headImage.image = [LocalFileManager getImageForKey:@"myUserImg"];
//    } else {
//        self.headImage.image = [UIImage imageNamed:@"图层-2.png"];
//    }
    
}

- (void)setModel:(HPMe *)me
{
    self.nickName.text = me.username;
    NSRange range = NSMakeRange(0, 10);
    NSString *str = [((HPChildren *)me.children[0]).cBirthday substringWithRange:range];
    self.BabyName.text = [NSString stringWithFormat:@"%@ %@",((HPChildren *)me.children[0]).cName,str];
    UIImage *placeImage;
    if ([LocalFileManager getImageForKey:@"myUserImg"]) {
        placeImage = [LocalFileManager getImageForKey:@"myUserImg"];
    }else{
        placeImage = [UIImage imageNamed:@"图层-2"];
    }
    
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:me.pHeadUrl] placeholderImage:placeImage completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        [LocalFileManager saveImage:image forKey:@"myUserImg"];
    }];
    
//    [self setHeadWithImage:me.pHeadUrl];

}

- (void)setHeadWithImage:(NSString *)headUrl
{
    [GPAFNetworking3 get:headUrl progress:nil success:^(id  _Nonnull responseObject) {
        UIImage *image = [UIImage imageWithData:responseObject];
        [LocalFileManager saveImage:image forKey:@"myUserImg"];
    } failure:^(NSString * _Nonnull errorLD) {
        
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
